import getColorArr from './color'
//获取dom style
const getStyle = (domName, domQuery) => {
  const dom = document.querySelector(domName)
  if (dom) {
    let style = window.getComputedStyle(dom)
    return style[domQuery]
  }
}
//设置dom style
const setStyle = (domName, domQuery, domQueryValue) => {
  const dom = document.querySelector(domName)
  if (dom) {
    dom.style.domQuery = domQueryValue
    dom.style[domQuery] = domQueryValue
  }
}

//设置主题色
const setTheme = (colorName, color) => {
  const el = document.documentElement
  const oldColor = getComputedStyle(el).getPropertyValue(`--c-base`).trim()
  let gradient = getColorArr.gradientColor(color, oldColor, 10)
  gradient.forEach((item, index) => {
    if (index === 0) el.style.setProperty(`${colorName}`, item)
    if (index === 9) return
    el.style.setProperty(`${colorName}-light-${index + 1}`, item)
  })
}

const setLocal = (key, value) => {
  if (JSON.parse(localStorage.getItem(key) || '')) {
    localStorage.setItem(key, value)
  }
}

export default { getStyle, setStyle, setTheme, setLocal }
